﻿using System.Diagnostics;



using zijian666;

namespace NUnitTest;


public class UnitTest3
{
    public UnitTest3()
    {
        if (!Debugger.IsAttached)
        {
            _ = DiagnosticListener.AllListeners.Subscribe(new DiagnosticObserver());
        }
    }

    [Test]
    public void 自定义强转()
    {
        var i = 11;
        var my = i.To<MyClass>();
        Assert.AreEqual(i, my.ID);
    }

    public class MyClass
    {
        public int ID { get; set; }
        public static explicit operator MyClass(int i) => new MyClass() { ID = i };
    }

    [Test]
    public void 自定义隐转()
    {
        var my = new MyClass2 { ID = 100 };
        var i = my.To<int>();
        Assert.AreEqual(i, my.ID);
    }

    public class MyClass2
    {
        public int ID { get; set; }
        public static implicit operator int(MyClass2 my) => my?.ID ?? -1;
    }
}
